<template>
	<view class="addJia">
		<view class="addJia-main">
			<view class="addJia-main-li" v-for="(item, index) of list" :key="index">
				<view class="addJia-main-li-left">
					<image class="addJia-main-li-left-img" :src=item.attributeLogo mode=""></image>
				</view>
				<view class="addJia-main-li-right">
					<view class="addJia-main-li-right-one">
						{{item.attributeName}}
					</view>
					<view class="addJia-main-li-right-two">
						<text class="addJia-main-li-right-two-mian" v-if="item.isPost == 1">
							包邮 偏远地区补差价
						</text>
						<text class="baoyou-no" v-else>不包邮</text>
					</view>
					<view class="addJia-main-li-right-three">
						<view class="addJia-main-li-right-three-left">
							<text>建议零售价: </text>
							<text class="addJia-main-li-right-three-left-txt2">￥{{item.attributeSalePrice}}</text>
						</view>
						<view class="addJia-main-li-right-three-right">
							<text class="addJia-main-li-right-three-right-txt1">￥</text>
							<input v-model="item.count" class="addJia-main-li-right-three-right-input" placeholder-class="inputplace" placeholder="请输入价格" type="number"
								value="" />
							<text class="addJia-main-li-right-three-right-txt2">/{{item.partsUnit}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="addJia-btn">
			<view class="addJia-btn-one" @click="cli_clear">
				取消
			</view>
			<view class="addJia-btn-two" @click="cli_ljsj">
				立即上架
			</view>
		</view>
	</view>
</template>

<script>
	import allapi from '../api/index.js'
	export default {
		data() {
			return {
				id: '',
				agentId: uni.getStorageSync('agentId'),
				list: []
			}
		},
		onLoad(val) {
			if (val.id) {
				this.id = val.id
			}
		},
		mounted() {
			this.getPartsAttributeByPartsId()
		},
		methods: {
			// 点击取消
			cli_clear () {
				uni.navigateBack();
			},
			// 点击立即上架
			cli_ljsj () {
				let list = this.list
				let putList
				let val = list.filter(item=> {
					if (item.count) {
						return item
					}
				})
				if (val.length > 0) {
					putList = val.map(item => {
						console.log(item);
						return {
							attributeId: item.id,
							price: item.count,
						}
					})
					console.log(putList);
					this.preserveMyParts(putList)
				}else {
					uni.showToast({
						title:'请输入产品售价',
						icon:'none'
					})
				}
			},
			// 批量上架到我的店铺
			preserveMyParts (partsJson) {
				uni.request({
					url: allapi.preserveMyParts,
					data: {
						agentId: this.agentId,
						partsId: this.id,
						partsJson: partsJson
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon:'none'
						})
						uni.navigateBack()
					}
				})
			},
			// 获取列表
			getPartsAttributeByPartsId () {
				uni.request({
					url: allapi.getPartsAttributeByPartsId,
					data: {
						partsId: this.id
					},
					success: (res) => {
						console.log(res);
						let dat = res.data.data
						this.list = dat
					}
				})
			},
		}
	}
</script>

<style scoped>
	.addJia {
		position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		display: flex;
		flex-direction: column;
		background: #FFFFFF;
	}

	.addJia-main {
		flex: 1;
		overflow: auto;
	}

	.addJia-btn {
		padding-top: 20rpx;
		height: 120rpx;
		align-content: center;
		padding: 0 32rpx;
		display: flex;
		justify-content: space-between;
	}

	.addJia-btn-one {
		width: 296rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		background: #F3F5F6;
		border-radius: 44rpx;
		font-size: 32rpx;
		color: #333333;
	}

	.addJia-btn-two {
		width: 296rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		background: linear-gradient(90deg, #2ACE52 0%, #1DC248 100%);
		border-radius: 44rpx;
		font-size: 32rpx;
		color: #FFFFFF;
	}

	.addJia-main-li {
		border-bottom: 2rpx solid #EEEEEE;
		margin: 0 24rpx;
		margin-left: 48rpx;
		padding: 24rpx 0;
		display: flex;
	}

	.addJia-main-li-left-img {
		width: 160rpx;
		height: 160rpx;
		border-radius: 12rpx;
		/* background: red; */
	}
	.addJia-main-li-right {
		flex: 1;
		margin-left: 24rpx;
	}
	.addJia-main-li-right-one {
		line-height: 40rpx;
		color: #333333;
		font-size: 28rpx;
	}

	.addJia-main-li-right-two {
		margin-top: 18rpx;
	}

	.addJia-main-li-right-two-mian {
		height: 36rpx;
		line-height: 36rpx;
		text-align: center;
		border-radius: 6rpx;
		border: 4rpx solid #28CD50;
		padding: 4rpx 12rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: #28CD50;
	}

	.addJia-main-li-right-three {
		display: flex;
		justify-content: space-between;
		margin-top: 20rpx;
		align-items: center;
	}

	.addJia-main-li-right-three-left {
		height: 40rpx;
		line-height: 40rpx;
		font-size: 22rpx;
		font-weight: 400;
		color: #999999;
	}

	.addJia-main-li-right-three-left-txt2 {
		font-size: 28rpx;
	}
	.addJia-main-li-right-three-right {
		display: flex;
		align-items: center;
	}
	.addJia-main-li-right-three-right-input {
		width: 128rpx;
		height: 48rpx;
		border-radius: 8rpx;
		border: 2rpx solid #CCCCCC;
		text-align: center;
		line-height: 48rpx;
		font-size: 28rpx;
		color: #333333;
		margin: 0 12rpx;
		
	}
	/deep/ .addJia-main-li-right-three-right-input-place{
		font-size: 20rpx;
	}
	.addJia-main-li-right-three-right-txt1 {
		font-size: 24rpx;
		font-weight: 400;
		color: #333333;
	}

	.addJia-main-li-right-three-right-txt2 {
		font-size: 24rpx;
		color: #666666;
		font-weight: 400;
	}
</style>
